package com.test.amqp;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

;

/**
 * 消息队列的配置类
 */
@Configuration
public class RabbitDirectConfig {

    public final static String DIRECT_NAME = "root-direct";

    @Bean
    Queue queue() {
        return new Queue("root-queue");
    }

    @Bean
    DirectExchange directExchange() {
        //参数1是名字，参数2是重启后是否以然有效，参数3是长期未使用时是否删除
        return new DirectExchange(DIRECT_NAME, true, false);
    }

    /**
     * 创建一个Binding对象将Exchange和Queue绑定再一起
     *
     * @return
     */
    @Bean
    Binding binding() {
        return BindingBuilder.bind(queue()).to(directExchange()).with("direct");
    }
}
